From: Ewan Mellor Date: Fri, 29 Dec 2006 20:17:01 +0000 (+0000) Subject: Resurrect cset 13174:766eec31afab, with one fix -- pass the fallback flag to X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15422^2~117 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=95fac2786b489658ae8af7916a2aea5daffef685;p=xen.git Resurrect cset 13174:766eec31afab, with one fix -- pass the fallback flag to gettext.translation so that this module works if the message database is missing (it's still an optional part of the build). Signed-off-by: Ewan Mellor --- diff --git a/tools/python/xen/xm/XenAPI.py b/tools/python/xen/xm/XenAPI.py index a8cfce8751..8d58c3f7f6 100644 --- a/tools/python/xen/xm/XenAPI.py +++ b/tools/python/xen/xm/XenAPI.py @@ -50,7 +50,7 @@ import xmlrpclib import xen.util.xmlrpclib2 -gettext.install('xen-xm') +translation = gettext.translation('xen-xm', fallback = True) class Failure(Exception): def __init__(self, details): @@ -68,7 +68,7 @@ class Failure(Exception): def __str__(self): try: - return _(self.details[0]) % self._details_map() + return translation.ugettext(self.details[0]) % self._details_map() except TypeError, exn: return "Message database broken: %s.\nXen-API failure: %s" % \ (exn, str(self.details)) @@ -108,6 +108,8 @@ class Session(xen.util.xmlrpclib2.ServerProxy): encoding, verbose, allow_none) self._session = None + self.last_login_method = None + self.last_login_params = None def xenapi_request(self, methodname, params): @@ -121,7 +123,11 @@ class Session(xen.util.xmlrpclib2.ServerProxy): result = _parse_result(getattr(self, methodname)(*full_params)) if result == _RECONNECT_AND_RETRY: retry_count += 1 - self._login(self.last_login_method, self.last_login_params) + if self.last_login_method: + self._login(self.last_login_method, + self.last_login_params) + else: + raise xmlrpclib.Fault(401, 'You must log in') else: return result raise xmlrpclib.Fault( @@ -172,10 +178,18 @@ class _Dispatcher: def __init__(self, send, name): self.__send = send self.__name = name + + def __repr__(self): + if self.__name: + return '' % self.__name + else: + return '' + def __getattr__(self, name): if self.__name is None: return _Dispatcher(self.__send, name) else: return _Dispatcher(self.__send, "%s.%s" % (self.__name, name)) + def __call__(self, *args): return self.__send(self.__name, args)